//
//  EditViewController.m
//  XRSquare
//
//  Created by UaenaMo on 2018/8/14.
//  Copyright © 2018年 UaenaMo. All rights reserved.
//

#import "EditViewController.h"
#import "PGDatePickManager.h"
#import "ZhiYeViewController.h"
#import "CityViewController.h"
#import <Qiniu/QiniuSDK.h>
#import <UMShare/UMShare.h>
@import CoreLocation;
#define IOS8 [[[UIDevice currentDevice] systemVersion]floatValue]>=8.0
@interface EditViewController ()<UIScrollViewDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate,PGDatePickerDelegate,zhiyeDelegate,citySelectDelegate>
{
    UIScrollView * currentScrollView;

    UIImageView * imageView;
    UILabel * titleLabel;
    UITextField * nickNameTextField;
    UILabel * sexLabel;
    UILabel * sexConntent;
    UILabel * birthLabel;
    UILabel * bitthContent;
    UILabel * shenfenLabel;
    UILabel * shenfenContent;

    UILabel * zhiyeLabel;
    UILabel * zhiyeConent;

    UILabel * workLabel;
    UITextField * workContent;
    UILabel * schoolLabel;
    UITextField * schoolContent;
    UILabel * locaitonLabel;
    UILabel * locaitonContent;
    UILabel * bioLabel;
    UITextField * bioContent;
    UILabel * phoneLabel;
    UILabel * phoneContent;
    UILabel * mailLabel;
    UITextField * mailContent;
    UILabel * qqLabel;
    UIButton * qqLabelContent;
    UILabel * wechatLabel;
    UIButton * wechatContent;
    UILabel * ecLabel;
    UITextField * ecContent;
    UILabel * connectionLabel;
    UITextField * connectionContent;
    UILabel * ecmobileLabel;
    UITextField * ecmobileContent;
    UILabel * notificationLabel;
    UISwitch * nSwitch;

    UIView * contentView;

    NSString * nickName;
    NSString * sex;
    NSString * birth;
    NSString * identity;
    NSString * identity2;
    NSString * work;
    NSString * school;
    NSString * provincel;
    NSString * cityl;
    NSString * districtl;
    NSString * bio;
    NSString * phone;
    NSString * mail;
    NSString * qq;
    NSString * wechat;
    NSString * emContact;
    NSString * connection;
    NSString * emPhone;
    int notification;
    NSString * province;
    NSString * city;
}
@property(nonatomic,retain)CLLocationManager *locationManager;

@end

@implementation EditViewController


//开始定位
-(void)locationStart{
    //判断定位操作是否被允许

    if([CLLocationManager locationServicesEnabled]) {
        self.locationManager = [[CLLocationManager alloc] init] ;
        self.locationManager.delegate = self;
        //设置定位精度
        self.locationManager.desiredAccuracy=kCLLocationAccuracyBest;
        self.locationManager.distanceFilter = kCLLocationAccuracyHundredMeters;//每隔多少米定位一次（这里的设置为每隔百米)
        if (IOS8) {
            //使用应用程序期间允许访问位置数据
            [self.locationManager requestWhenInUseAuthorization];
        }
        // 开始定位
        [self.locationManager startUpdatingLocation];
    }else {
        //提示用户无法进行定位操作
        NSLog(@"%@",@"定位服务当前可能尚未打开，请设置打开！");

    }
}
#pragma mark - CoreLocation Delegate

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations

{
    //系统会一直更新数据，直到选择停止更新，因为我们只需要获得一次经纬度即可，所以获取之后就停止更新
    [self.locationManager stopUpdatingLocation];
    //此处locations存储了持续更新的位置坐标值，取最后一个值为最新位置，如果不想让其持续更新位置，则在此方法中获取到一个值之后让locationManager stopUpdatingLocation
    CLLocation *currentLocation = [locations lastObject];

    //获取当前所在的城市名
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    //根据经纬度反向地理编译出地址信息
    [geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *array, NSError *error)
     {
         if (array.count >0)
         {

             [[NSUserDefaults
               standardUserDefaults] setObject:[NSArray arrayWithObjects:@"zh-hans",
                                                nil] forKey:@"AppleLanguages"];

             CLPlacemark *placemark = [array objectAtIndex:0];
             //获取城市
             NSString *currCity = placemark.locality;
             if (!currCity) {
                 //四大直辖市的城市信息无法通过locality获得，只能通过获取省份的方法来获得（如果city为空，则可知为直辖市）
                 currCity = placemark.administrativeArea;
             }

             province = placemark.administrativeArea;
             city = currCity;

         } else if (error ==nil && [array count] == 0)
         {
             NSLog(@"No results were returned.");
         }else if (error !=nil)
         {
             NSLog(@"An error occurred = %@", error);
         }

     }];

}
- (void)locationManager:(CLLocationManager *)manager
       didFailWithError:(NSError *)error {
    if (error.code ==kCLErrorDenied) {
        // 提示用户出错原因，可按住Option键点击 KCLErrorDenied的查看更多出错信息，可打印error.code值查找原因所在
    }

}

-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])
    {
        province = @"辽宁省";
        city = @"大连市";
        nickName = @"";
        sex = @"";
        birth = @"";
        identity = @"";
        work = @"";
        school = @"";
        bio = @"";
        phone = @"";
        mail = @"";
        qq = @"";
        wechat = @"";
        emContact = @"";
        connection = @"";
        emPhone = @"";
    }
    return self;
}

-(void)loadData:(NSDictionary *)data
{
    [imageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",[data objectForKey:@"PicURL"],[data objectForKey:@"HeadPic"]]]];
    nickNameTextField.text = [NSString stringWithFormat:@"%@",[data objectForKey:@"Name"]];
    sexConntent.text = [NSString stringWithFormat:@"%@",[data objectForKey:@"Sex"]];
    bitthContent.text = [NSString stringWithFormat:@"%@",[data objectForKey:@"BirthDay"]];
    shenfenContent.text = [NSString stringWithFormat:@"%@",[data objectForKey:@"Identify1"]];
    zhiyeConent.text = [NSString stringWithFormat:@"%@",[data objectForKey:@"Identify2"]];
    workContent.text = [NSString stringWithFormat:@"%@",[data objectForKey:@"Company"]];
    schoolContent.text = [NSString stringWithFormat:@"%@",[data objectForKey:@"School"]];
    locaitonContent.text = [NSString stringWithFormat:@"%@ %@ %@",[data objectForKey:@"Province"],[data objectForKey:@"City"],[data objectForKey:@"District"]];
    bioContent.text = [NSString stringWithFormat:@"%@",[data objectForKey:@"Intro"]];
    phoneContent.text = [NSString stringWithFormat:@"%@",[data objectForKey:@"MobileNumber"]];
    mailContent.text = [NSString stringWithFormat:@"%@",[data objectForKey:@"Email"]];
    NSString * qqt = [NSString stringWithFormat:@"%@",[data objectForKey:@"AuthQQ"]];
    NSString * wechatt = [NSString stringWithFormat:@"%@",[data objectForKey:@"AuthWechat"]];

    [qqLabelContent setTitle:qqt forState:UIControlStateNormal];
    [wechatContent setTitle:wechatt forState:UIControlStateNormal];

    ecContent.text = [NSString stringWithFormat:@"%@",[data objectForKey:@"EmergencyContact_Name"]];
    connectionContent.text = [NSString stringWithFormat:@"%@",[data objectForKey:@"EmergencyContact_RelationShip"]];
    ecmobileContent.text = [NSString stringWithFormat:@"%@",[data objectForKey:@"EmergencyContact_Phone"]];
    nSwitch.on = [[NSString stringWithFormat:@"%@",[data objectForKey:@"JobPush"]]intValue];

    if ([nickNameTextField.text isEqualToString:@"<null>"]) {
        nickNameTextField.text = @"";
    }
    if ([sexConntent.text isEqualToString:@"<null>"]) {
        sexConntent.text = @"";
    }
    if ([bitthContent.text isEqualToString:@"<null>"]) {
        bitthContent.text = @"";
    }
    if ([shenfenContent.text isEqualToString:@"<null>"]) {
        shenfenContent.text = @"";
    }
    if ([zhiyeConent.text isEqualToString:@"<null>"]) {
        zhiyeConent.text = @"";
    }
    if ([workContent.text isEqualToString:@"<null>"]) {
        workContent.text = @"";
    }
    if ([schoolContent.text isEqualToString:@"<null>"]) {
        schoolContent.text = @"";
    }
    if ([locaitonContent.text isEqualToString:@"<null>"]) {
        locaitonContent.text = @"";
    }
    if ([bioContent.text isEqualToString:@"<null>"]) {
        bioContent.text = @"";
    }
    if ([phoneContent.text isEqualToString:@"<null>"]) {
        phoneContent.text = @"";
    }
    if ([mailContent.text isEqualToString:@"<null>"]) {
        mailContent.text = @"";
    }
    if ([qqLabelContent.titleLabel.text isEqualToString:@"<null>"]) {
        [qqLabelContent setTitle:@"去绑定" forState:UIControlStateNormal];
    }
    if ([wechatContent.titleLabel.text isEqualToString:@"<null>"]) {
        [wechatContent setTitle:@"去绑定" forState:UIControlStateNormal];
    }
    if ([ecContent.text isEqualToString:@"<null>"]) {
        ecContent.text = @"";
    }
    if ([connectionContent.text isEqualToString:@"<null>"]) {
        connectionContent.text = @"";
    }
    if ([ecmobileContent.text isEqualToString:@"<null>"]) {
        ecmobileContent.text = @"";
    }

    nickName = nickNameTextField.text;
    sex = sexConntent.text;
    birth = bitthContent.text;
    identity = shenfenContent.text;
    identity2 = zhiyeConent.text;

    work = workContent.text;
    school = schoolContent.text;
    provincel = [data objectForKey:@"Province"];
    cityl = [data objectForKey:@"City"];
    districtl = [data objectForKey:@"District"];
    bio = bioContent.text;
    phone = phoneContent.text;
    mail = mailContent.text;
    emContact = ecContent.text;
    connection = connectionContent.text;
    emPhone = ecmobileContent.text;
    notification = [[NSString stringWithFormat:@"%@",[data objectForKey:@"JobPush"]]intValue];

}

-(void)backAction
{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)finishAction
{
    [NetRequestCenter uptokenwithbucket:@"0" result:^(BOOL success, NSDictionary *resultDic) {
        if (success)
        {
            NSString * token = [resultDic objectForKey:@"uptoken"];
            UIImage * oriImage = imageView.image;
            NSData * imageData = UIImageJPEGRepresentation(oriImage, 0.5);
            QNUploadOption * option=[[QNUploadOption alloc] initWithProgressHandler:^(NSString *key, float percent) {
                NSLog(@"key=%@ ,percent=%f",key,percent);
            }];

            QNUploadManager * upload=[[QNUploadManager alloc] init];

            [upload putData:imageData key:[[token componentsSeparatedByString:@":"]firstObject] token:token complete:^(QNResponseInfo *info, NSString *key, NSDictionary *res) {
                NSLog(@"statusCode=%d",info.statusCode);
                NSLog(@"%@",res);

                if(info.statusCode==200)
                {
                    [NetRequestCenter updateUserInfoWIthheadpic:[res objectForKey:@"hash"] nickname:nickNameTextField.text sex:sex birthday:birth identify:identity identify2:identity2 school:schoolContent.text company:workContent.text province:provincel city:cityl district:districtl jobpush:[NSString stringWithFormat:@"%d",notification] intro:bio ecname:ecContent.text ecrelationship:connectionContent.text ecphone:ecmobileContent.text result:^(BOOL success, NSDictionary *resultDic) {
                        if (success)
                        {
                            [self.navigationController popViewControllerAnimated:YES];
                        }
                        else
                        {
                            [SVProgressHUD showErrorWithStatus:[resultDic objectForKey:@"message"]];
                        }
                    }];
                }
                else
                {
                    [SVProgressHUD showErrorWithStatus:[info.error localizedDescription]];

                }

            } option:option];
        }
    }];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.tintColor = [UIColor grayColor];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] style:UIBarButtonItemStylePlain target:self action:@selector(backAction)];

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(finishAction)];

    currentScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    currentScrollView.delegate = self;
    [self.view addSubview:currentScrollView];

    imageView = [[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth - 60, 10, 50, 50)];
    imageView.layer.cornerRadius = 25;
    imageView.clipsToBounds = YES;
    imageView.backgroundColor = [UIColor blackColor];
    imageView.userInteractionEnabled = YES;
    [currentScrollView addSubview:imageView];

    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(selectImage)];
    [imageView addGestureRecognizer:tap];

    CGFloat height = 70;

    {
        titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, 150, 20)];
        titleLabel.font = [UIFont systemFontOfSize:15];
        titleLabel.text = @"昵称";
        [currentScrollView addSubview:titleLabel];

        nickNameTextField = [[UITextField alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth - 20, 20)];
        nickNameTextField.textAlignment = NSTextAlignmentRight;
        nickNameTextField.placeholder = @"";
        [currentScrollView addSubview:nickNameTextField];

        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [currentScrollView addSubview:line];

        height += 40;
    }
    {
        sexLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, 150, 20)];
        sexLabel.font = [UIFont systemFontOfSize:15];
        sexLabel.text = @"性别";
        [currentScrollView addSubview:sexLabel];

        sexConntent = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth - 20, 20)];
        sexConntent.textAlignment = NSTextAlignmentRight;
        [currentScrollView addSubview:sexConntent];

        UIButton * buttom = [[UIButton alloc]initWithFrame:CGRectMake(0, height, ScreenWidth, 40)];
        [buttom addTarget:self action:@selector(sexAction) forControlEvents:UIControlEventTouchUpInside];
        [currentScrollView addSubview:buttom];

        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [currentScrollView addSubview:line];

        height += 40;

    }
    {
        birthLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, 150, 20)];
        birthLabel.font = [UIFont systemFontOfSize:15];
        birthLabel.text = @"出生日期";
        [currentScrollView addSubview:birthLabel];

        bitthContent = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth - 20, 20)];
        bitthContent.textAlignment = NSTextAlignmentRight;
        [currentScrollView addSubview:bitthContent];

        UIButton * buttom = [[UIButton alloc]initWithFrame:CGRectMake(0, height, ScreenWidth, 40)];
        [buttom addTarget:self action:@selector(birthAction) forControlEvents:UIControlEventTouchUpInside];
        [currentScrollView addSubview:buttom];

        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [currentScrollView addSubview:line];

        height += 40;
    }
    {
        shenfenLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, 150, 20)];
        shenfenLabel.font = [UIFont systemFontOfSize:15];
        shenfenLabel.text = @"身份";
        [currentScrollView addSubview:shenfenLabel];

        shenfenContent = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth - 20, 20)];
        shenfenContent.textAlignment = NSTextAlignmentRight;
        [currentScrollView addSubview:shenfenContent];

        UIButton * buttom = [[UIButton alloc]initWithFrame:CGRectMake(0, height, ScreenWidth, 40)];
        [buttom addTarget:self action:@selector(shenfenAction) forControlEvents:UIControlEventTouchUpInside];
        [currentScrollView addSubview:buttom];

        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [currentScrollView addSubview:line];

        height += 40;
    }
    {
        zhiyeLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, 150, 20)];
        zhiyeLabel.font = [UIFont systemFontOfSize:15];
        zhiyeLabel.text = @"职业";
        [currentScrollView addSubview:zhiyeLabel];

        zhiyeConent = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth - 20, 20)];
        zhiyeConent.textAlignment = NSTextAlignmentRight;
        [currentScrollView addSubview:zhiyeConent];

        UIButton * buttom = [[UIButton alloc]initWithFrame:CGRectMake(0, height, ScreenWidth, 40)];
        [buttom addTarget:self action:@selector(zhiyeAction) forControlEvents:UIControlEventTouchUpInside];
        [currentScrollView addSubview:buttom];

        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [currentScrollView addSubview:line];
    }

    contentView = [[UIView alloc]initWithFrame:CGRectMake(0, height + 1, ScreenWidth, 0)];
    contentView.backgroundColor  = [UIColor whiteColor];
    [currentScrollView addSubview:contentView];
    height = 0;
    {
        workLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, 150, 20)];
        workLabel.font = [UIFont systemFontOfSize:15];
        workLabel.text = @"工作单位";
        [contentView addSubview:workLabel];

        workContent = [[UITextField alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth - 20, 20)];
        workContent.textAlignment = NSTextAlignmentRight;
        workContent.placeholder = @"";
        [contentView addSubview:workContent];

        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [contentView addSubview:line];

        height += 40;
    }
    {
        schoolLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, 150, 20)];
        schoolLabel.font = [UIFont systemFontOfSize:15];
        schoolLabel.text = @"现就读(已毕业)学校";
        [contentView addSubview:schoolLabel];

        schoolContent = [[UITextField alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth - 20, 20)];
        schoolContent.textAlignment = NSTextAlignmentRight;
        schoolContent.placeholder = @"";
        [contentView addSubview:schoolContent];

        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [contentView addSubview:line];

        height += 40;
    }
    {
        locaitonLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, 150, 20)];
        locaitonLabel.font = [UIFont systemFontOfSize:15];
        locaitonLabel.text = @"地址";
        [contentView addSubview:locaitonLabel];

        locaitonContent = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth - 20, 20)];
        locaitonContent.textAlignment = NSTextAlignmentRight;
        [contentView addSubview:locaitonContent];

        UIButton * buttom = [[UIButton alloc]initWithFrame:CGRectMake(0, height, ScreenWidth, 40)];
        [buttom addTarget:self action:@selector(locationAction) forControlEvents:UIControlEventTouchUpInside];
        [contentView addSubview:buttom];

        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [contentView addSubview:line];

        height += 40;
    }
    {
        bioLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, 150, 20)];
        bioLabel.font = [UIFont systemFontOfSize:15];
        bioLabel.text = @"个人简介";
        [contentView addSubview:bioLabel];

        bioContent = [[UITextField alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth - 20, 20)];
        bioContent.textAlignment = NSTextAlignmentRight;
        bioContent.placeholder = @"";
        [contentView addSubview:bioContent];

        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [contentView addSubview:line];

        height += 40;
    }
    {
        phoneLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, 150, 20)];
        phoneLabel.font = [UIFont systemFontOfSize:15];
        phoneLabel.text = @"手机";
        [contentView addSubview:phoneLabel];

        phoneContent = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth - 20, 20)];
        phoneContent.textAlignment = NSTextAlignmentRight;
        [contentView addSubview:phoneContent];

        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [contentView addSubview:line];

        height += 40;
    }
    {
        mailLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, 150, 20)];
        mailLabel.font = [UIFont systemFontOfSize:15];
        mailLabel.text = @"邮箱";
        [contentView addSubview:mailLabel];

        mailContent = [[UITextField alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth - 20, 20)];
        mailContent.textAlignment = NSTextAlignmentRight;
        mailContent.placeholder = @"";
        [contentView addSubview:mailContent];

        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [contentView addSubview:line];

        height += 40;
    }
    {
        qqLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, 150, 20)];
        qqLabel.font = [UIFont systemFontOfSize:15];
        qqLabel.text = @"QQ";
        [contentView addSubview:qqLabel];

        qqLabelContent = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth - 90, height + 10, 80, 20)];
        qqLabelContent.titleLabel.font = [UIFont systemFontOfSize:12];
        [qqLabelContent setTitleColor:themeColor forState:UIControlStateNormal];
        qqLabelContent.layer.cornerRadius = 10;
        qqLabelContent.layer.borderWidth = 1;
        qqLabelContent.layer.borderColor = themeColor.CGColor;
        [qqLabelContent addTarget:self action:@selector(qqAction) forControlEvents:UIControlEventTouchUpInside];

        [contentView addSubview:qqLabelContent];



        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [contentView addSubview:line];

        height += 40;
    }
    {
        wechatLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, 150, 20)];
        wechatLabel.font = [UIFont systemFontOfSize:15];
        wechatLabel.text = @"微信";
        [contentView addSubview:wechatLabel];

        wechatContent = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth - 90, height + 10, 80, 20)];
        wechatContent.titleLabel.font = [UIFont systemFontOfSize:12];
        [wechatContent setTitleColor:themeColor forState:UIControlStateNormal];
        wechatContent.layer.cornerRadius = 10;
        wechatContent.layer.borderWidth = 1;
        wechatContent.layer.borderColor = themeColor.CGColor;
        [wechatContent addTarget:self action:@selector(wechatAction) forControlEvents:UIControlEventTouchUpInside];

        [contentView addSubview:wechatContent];


        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [contentView addSubview:line];

        height += 40;
    }
    {
        ecLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, 150, 20)];
        ecLabel.font = [UIFont systemFontOfSize:15];
        ecLabel.text = @"紧急联系人";
        [contentView addSubview:ecLabel];

        ecContent = [[UITextField alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth - 20, 20)];
        ecContent.textAlignment = NSTextAlignmentRight;
        [contentView addSubview:ecContent];

        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [contentView addSubview:line];

        height += 40;
    }
    {
        connectionLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, 150, 20)];
        connectionLabel.font = [UIFont systemFontOfSize:15];
        connectionLabel.text = @"与您的关系";
        [contentView addSubview:connectionLabel];

        connectionContent = [[UITextField alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth - 20, 20)];
        connectionContent.textAlignment = NSTextAlignmentRight;
        connectionContent.placeholder = @"";
        [contentView addSubview:connectionContent];

        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [contentView addSubview:line];

        height += 40;
    }
    {
        ecmobileLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, 150, 20)];
        ecmobileLabel.font = [UIFont systemFontOfSize:15];
        ecmobileLabel.text = @"紧急联系电话";
        [contentView addSubview:ecmobileLabel];

        ecmobileContent = [[UITextField alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth - 20, 20)];
        ecmobileContent.textAlignment = NSTextAlignmentRight;
        ecmobileContent.placeholder = @"";
        [contentView addSubview:ecmobileContent];

        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [contentView addSubview:line];

        height += 40;
    }
    {
        notificationLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, 150, 20)];
        notificationLabel.font = [UIFont systemFontOfSize:15];
        notificationLabel.text = @"开启求职推送";
        [contentView addSubview:notificationLabel];

        nSwitch = [[UISwitch alloc]initWithFrame:CGRectMake(ScreenWidth - 65, height + 5, ScreenWidth - 20, 20)];
        [nSwitch addTarget:self action:@selector(nfSwitch:) forControlEvents:UIControlEventTouchUpInside];
        [contentView addSubview:nSwitch];

        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [contentView addSubview:line];

        height += 40;
    }
    contentView.frame = CGRectMake(0, contentView.frame.origin.y, ScreenWidth, height);
    contentView.backgroundColor = [UIColor whiteColor];
    currentScrollView.contentSize = CGSizeMake(ScreenWidth, height + contentView.frame.origin.y);
    [self loadData:self.data];
}

-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    [nickNameTextField resignFirstResponder];
    [workContent resignFirstResponder];
    [schoolContent resignFirstResponder];
    [bioContent resignFirstResponder];
    [mailContent resignFirstResponder];
    [ecContent resignFirstResponder];
    [connectionContent resignFirstResponder];
    [ecmobileContent resignFirstResponder];
}

-(void)nfSwitch:(UISwitch *)nswitch
{
    nSwitch.selected = !nSwitch.selected;
    notification = nswitch.on;
}

-(void)selectImage
{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil
                                                                             message:nil
                                                                      preferredStyle:UIAlertControllerStyleActionSheet];

    UIAlertAction * timeOrder = [UIAlertAction actionWithTitle:@"相机" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        UIImagePickerController * imagePicker = [[UIImagePickerController alloc]init];
        imagePicker.delegate = self;
        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        imagePicker.allowsEditing = YES;
        [self presentViewController:imagePicker animated:YES completion:nil];
    }];
    UIAlertAction * collectionOrder = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        UIImagePickerController * imagePicker = [[UIImagePickerController alloc]init];
        imagePicker.delegate = self;
        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        imagePicker.allowsEditing = YES;
        [self presentViewController:imagePicker animated:YES completion:nil];
    }];
    UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"Cancel Action");
    }];

    [alertController addAction:timeOrder];
    [alertController addAction:collectionOrder];
    [alertController addAction:cancelAction];

    [self presentViewController:alertController animated:YES completion:nil];
}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
    UIImage * selectedImage = [info objectForKey:UIImagePickerControllerOriginalImage];

    imageView.image = selectedImage;

    [self dismissViewControllerAnimated:picker completion:nil];
}

-(void)sexAction
{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil
                                                                             message:nil
                                                                      preferredStyle:UIAlertControllerStyleActionSheet];

    UIAlertAction * timeOrder = [UIAlertAction actionWithTitle:@"男" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        sexConntent.text = @"男";
        sex = @"0";
    }];
    UIAlertAction * collectionOrder = [UIAlertAction actionWithTitle:@"女" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        sexConntent.text = @"女";
        sex = @"1";
    }];
    UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }];

    [alertController addAction:timeOrder];
    [alertController addAction:collectionOrder];
    [alertController addAction:cancelAction];

    [self presentViewController:alertController animated:YES completion:nil];
}

-(void)birthAction
{
    PGDatePickManager *datePickManager = [[PGDatePickManager alloc]init];
    datePickManager.isShadeBackgroud = true;
    PGDatePicker *datePicker = datePickManager.datePicker;
    datePicker.delegate = self;
    datePicker.tag = 1;
    datePicker.datePickerType = PGPickerViewType2;
    datePicker.datePickerMode = PGDatePickerModeDate;
    [self presentViewController:datePickManager animated:false completion:nil];

}

-(void)shenfenAction
{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil
                                                                             message:nil
                                                                      preferredStyle:UIAlertControllerStyleActionSheet];

    UIAlertAction * timeOrder = [UIAlertAction actionWithTitle:@"学生" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        shenfenContent.text = @"学生";
        identity = @"学生";
        contentView.frame = CGRectMake(0, shenfenLabel.frame.origin.y + 31, ScreenWidth, contentView.frame.size.height);
    }];
    UIAlertAction * collectionOrder = [UIAlertAction actionWithTitle:@"工作" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        shenfenContent.text = @"工作";
        identity = @"工作";
        contentView.frame = CGRectMake(0, zhiyeLabel.frame.origin.y + 31, ScreenWidth, contentView.frame.size.height);
    }];
    UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }];

    [alertController addAction:timeOrder];
    [alertController addAction:collectionOrder];
    [alertController addAction:cancelAction];

    [self presentViewController:alertController animated:YES completion:nil];
}

-(void)zhiyeAction
{
    ZhiYeViewController * zhiye = [[ZhiYeViewController alloc]init];
    zhiye.delegate = self;
    [self.navigationController pushViewController:zhiye animated:YES];
}

-(void)selectedZhiYe:(NSString *)zhiy
{
    zhiyeConent.text = zhiy;
    identity2 = zhiy;
}

-(void)locationAction
{
    CityViewController * city = [[CityViewController alloc]init];
    city.delegate = self;
    [self.navigationController pushViewController:city animated:YES];
}

-(void)city:(NSString *)city province:(NSString *)province code:(NSString *)code
{
    locaitonContent.text = [NSString stringWithFormat:@"%@ %@ %@",province,city,districtl];
    provincel = province;
    cityl = city;
//    locaiton = code;
}


-(void)wechatAction
{
    if ([wechatContent.titleLabel.text isEqualToString:@"去绑定"])
    {
        [[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_WechatSession currentViewController:self completion:^(id result, NSError *error) {

            UMSocialUserInfoResponse *resp = result;
            NSLog(@"%@",resp);
            if (error) {

            }
            else
            {

                [NetRequestCenter wechatLoginWithProvince:province city:city openid:resp.openid unionid:resp.unionId accesstoken:resp.accessToken result:^(BOOL success, NSDictionary *resultDic) {
                    if (success) {

                        [wechatContent setTitle:resp.name forState:UIControlStateNormal];
                    }
                    else
                    {
                        [SVProgressHUD showErrorWithStatus:[resultDic objectForKey:@"message"]];

                    }
                }];
            }
        }];
    }
  else
  {
      [NetRequestCenter oauthunbindWithType:@"1" result:^(BOOL success, NSDictionary *resultDic) {
          if (success) {
              [wechatContent setTitle:@"去绑定" forState:UIControlStateNormal];
          }
          else
          {
              [SVProgressHUD showErrorWithStatus:[resultDic objectForKey:@"message"]];

          }
      }];
  }
}

-(void)qqAction
{
    if ([qqLabelContent.titleLabel.text isEqualToString:@"去绑定"])
    {
        [[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_QQ currentViewController:self completion:^(id result, NSError *error) {

            UMSocialUserInfoResponse *resp = result;

            if (error) {

            }
            else
            {
                [NetRequestCenter qqloginWithOpenid:resp.openid nickname:resp.name sex:resp.gender pic:resp.iconurl province:province city:city result:^(BOOL success, NSDictionary *resultDic) {
                    if (success) {
                        [qqLabelContent setTitle:resp.name forState:UIControlStateNormal];
                    }
                }];
            }
        }];
    }
    else
    {
        [NetRequestCenter oauthunbindWithType:@"0" result:^(BOOL success, NSDictionary *resultDic) {
            if (success) {
                [wechatContent setTitle:@"去绑定" forState:UIControlStateNormal];
            }
            else
            {
                [SVProgressHUD showErrorWithStatus:[resultDic objectForKey:@"message"]];

            }
        }];
    }
}


#pragma PGDatePickerDelegate
- (void)datePicker:(PGDatePicker *)datePicker didSelectDate:(NSDateComponents *)dateComponents {
    NSLog(@"dateComponents = %@", dateComponents);

    NSCalendar * calendar = [NSCalendar currentCalendar];
    NSDate * date = [calendar dateFromComponents:dateComponents];

    if (datePicker.tag == 1)
    {
        bitthContent.text = [NSString stringWithFormat:@"%d-%02d-%02ld",dateComponents.year,dateComponents.month,(long)dateComponents.day];
        birth = [NSString stringWithFormat:@"%d-%02d-%02ld",dateComponents.year,dateComponents.month,(long)dateComponents.day];
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
